package com.gyms.view.wheel;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.gyms.R;
import com.gyms.view.wheel.view.LoopView;
import com.gyms.view.wheel.view.OnItemSelectedListener;

import java.util.ArrayList;

import utils.EmptyUtils;

/**
 * 运动项目选择对话框
 */
public class SingleWheelDialog extends WheelDialog {

    private LoopView gymsCategory;

    private boolean isTop = false;

    private ArrayList<String> arrayList = null;//显示的数据集合
    private String selectedValue = null;


    public SingleWheelDialog(Context context, int animationStyle) {
        super(context, R.style.BottomViewTheme_Defalut);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.single_wheel;
    }


    private void initView() {
        gymsCategory = (LoopView) findViewById(R.id.wheel_gyms_category);
        if (EmptyUtils.isEmpty(arrayList)) {
            return;
        }
        if (arrayList.size() > 0) {
            //设置原始数据
            gymsCategory.setItems(arrayList);
            if (EmptyUtils.isNotEmpty(selectedValue)) {
                for (int i = 0; i < arrayList.size(); i++) {
                    if (selectedValue.equals(arrayList.get(i))) {
                        //设置初始位置
                        gymsCategory.setInitPosition(i);
                    }
                }
            }
            //设置字体大小
            gymsCategory.setTextSize(18);
        }
        //设置是否循环播放
        gymsCategory.setNotLoop();
        //滚动监听
        gymsCategory.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                if (dialogValues != null) {
                    dialogValues[0] = arrayList.get(index);
                }
                Log.d("debug", "Item " + index);
            }
        });
    }

    public void setData(String selectedValue, ArrayList<String> values) {
        this.arrayList = values;
        this.selectedValue = selectedValue;
        dialogValues = new String[1];
        dialogValues[0] = selectedValue;
    }


}